Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new nvtext minhash_permuted API #16756

Merged
merged 101 commits into from
Nov 12, 2024

Conversation

davidwendt
Copy link
Contributor

@davidwendt davidwendt commented Sep 5, 2024

Description

Introduce new nvtext minhash API that takes a single seed for hashing and 2 parameter vectors to calculate the minhash results from the seed hash:

std::unique_ptr<cudf::column> minhash_permuted(
  cudf::strings_column_view const& input,
  uint32_t seed,
  cudf::device_span<uint32_t const> parameter_a,
  cudf::device_span<uint32_t const> parameter_b,
  cudf::size_type width,
  rmm::cuda_stream_view stream,
  rmm::device_async_resource_ref mr);

The seed is used to hash the input using rolling set of substrings width characters wide.
The hashes are then combined with the values in parameter_a and parameter_b to calculate a set of 32-bit (or 64-bit) values for each row. Only the minimum value is returned per element of a and b when combined with all the hashes for a row. Each output row is a set of M values where M = parameter_a.size() = parameter_b.size()

This implementation is significantly faster than the current minhash which computes hashes for multiple seeds.

Included in this PR is also the minhash64_permuted() API that is identical but uses 64-bit values for the seed and the parameter values. Also included are new tests and a benchmark as well as the pylibcudf and cudf interfaces.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@davidwendt davidwendt added 2 - In Progress Currently a work in progress libcudf Affects libcudf (C++/CUDA) code. improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Sep 5, 2024
@davidwendt davidwendt self-assigned this Sep 5, 2024
@davidwendt davidwendt changed the base branch from branch-24.10 to branch-24.12 September 23, 2024 23:25
Copy link
Contributor

@Matt711 Matt711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we delete the minhash and minhash64 functions or wait until 25.02? For reference, they we're added in 24.12 #17021

python/cudf/cudf/tests/text/test_text_methods.py Outdated Show resolved Hide resolved
@davidwendt
Copy link
Contributor Author

Should we delete the minhash and minhash64 functions or wait until 25.02? For reference, they we're added in 24.12 #17021

I don't think we should remove the names without at least one release of deprecation.
Is there a way to mark them deprecated in python?

@wence-
Copy link
Contributor

wence- commented Nov 6, 2024

I don't think we should remove the names without at least one release of deprecation.

Agreed

Is there a way to mark them deprecated in python?

Yes: see https://docs.rapids.ai/api/cudf/stable/developer_guide/contributing_guide/#deprecating-and-removing-code

@davidwendt
Copy link
Contributor Author

I don't think we should remove the names without at least one release of deprecation.

Agreed

Is there a way to mark them deprecated in python?

Yes: see https://docs.rapids.ai/api/cudf/stable/developer_guide/contributing_guide/#deprecating-and-removing-code

So really what we plan to do is change the minhash_permuted to just minhash in 25.02 and get rid of the current minhash which takes different parameters. So I'm not sure what the deprecation warning should say exactly.

@davidwendt davidwendt requested a review from Matt711 November 6, 2024 18:35
@Matt711
Copy link
Contributor

Matt711 commented Nov 6, 2024

I don't think we should remove the names without at least one release of deprecation.

Agreed

Is there a way to mark them deprecated in python?

Yes: see https://docs.rapids.ai/api/cudf/stable/developer_guide/contributing_guide/#deprecating-and-removing-code

So really what we plan to do is change the minhash_permuted to just minhash in 25.02 and get rid of the current minhash which takes different parameters. So I'm not sure what the deprecation warning should say exactly.

Maybe something like this?

diff --git a/python/pylibcudf/pylibcudf/nvtext/minhash.pyx b/python/pylibcudf/pylibcudf/nvtext/minhash.pyx
index f1e012e60e..641af34eab 100644
--- a/python/pylibcudf/pylibcudf/nvtext/minhash.pyx
+++ b/python/pylibcudf/pylibcudf/nvtext/minhash.pyx
@@ -16,6 +16,7 @@ from pylibcudf.libcudf.types cimport size_type
 from pylibcudf.scalar cimport Scalar
 
 from cython.operator import dereference
+import warnings
 
 
 cpdef Column minhash(Column input, ColumnOrScalar seeds, size_type width=4):
@@ -40,6 +41,11 @@ cpdef Column minhash(Column input, ColumnOrScalar seeds, size_type width=4):
     Column
         List column of minhash values for each string per seed
     """
+    warnings.warn(
+        "Starting in version 25.02, the signature of this function will "
+        "be changed to match pylibcudf.nvtext.minhash_permuted.",
+        DeprecationWarning

And then maybe add a sentence to the docstring of minhash_permuted that the name will be changed in 25.02.

Copy link
Contributor

@Matt711 Matt711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the python changes LGTM.

Copy link
Contributor

@wence- wence- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two minor docstring formatting changes, and we should emit FutureWarning, not DeprecationWarning.

python/cudf/cudf/core/column/string.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/column/string.py Show resolved Hide resolved
python/pylibcudf/pylibcudf/nvtext/minhash.pyx Outdated Show resolved Hide resolved
python/pylibcudf/pylibcudf/nvtext/minhash.pyx Outdated Show resolved Hide resolved
Copy link
Member

@PointKernel PointKernel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean code.

Only two doc fixes and a question about shared memory type but nothing blocking. I also noticed several instances where () is used instead of {} for initialization. These are just minor nitpicks, though:

auto const hasher = HashFunction(seed);

auto const hash_str = cudf::string_view(itr, bytes);

cpp/include/nvtext/minhash.hpp Outdated Show resolved Hide resolved
cpp/include/nvtext/minhash.hpp Outdated Show resolved Hide resolved
cpp/src/text/minhash.cu Outdated Show resolved Hide resolved
@davidwendt
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit ccfc95a into rapidsai:branch-24.12 Nov 12, 2024
105 checks passed
@davidwendt davidwendt deleted the perf-minhash-highmem branch November 12, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team CMake CMake build issue improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.
Projects
Status: Done
Status: Landed
Development

Successfully merging this pull request may close these issues.

6 participants